package cc.xuanhaojituan.mongodb.controller;

import cc.xuanhaojituan.mongodb.dao.UserDao;
import cc.xuanhaojituan.mongodb.model.User;
import cc.xuanhaojituan.mongodb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author chenli
 * @create 2017-09-15
 */
@RestController
public class IndexController {

    @Autowired
    private UserService userService;

    @Autowired
    private UserDao userDao;

    @GetMapping("/save")
    public String save(){
        User user = new User();
        user.setUserName("陈李");
        user.setPassword("123456");
        user.setAddTime(new Date());
        userService.save(user);
        return "SUCCESS";
    }

    @GetMapping("/find")
    public User find(){
        return userDao.findByUserName("陈李");
    }
}